package cn.doctorpda.conference.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import cn.doctorpda.conference.R;
import cn.doctorpda.conference.utils.ImageUtils;
import cn.doctorpda.conference.view.callbackview.OnItemClickListener;

/**
 * Created by huangjinlong on 2016/5/18.
 */
public class ShareDialogAdapter extends RecyclerView.Adapter<ShareDialogAdapter.ViewHolder> {

    private Context mContext;
    private OnItemClickListener listener;

    private int[] drawableList = {
            R.drawable.ssdk_oks_classic_wechat,
            R.drawable.ssdk_oks_classic_qq,
            R.drawable.ssdk_oks_classic_wechatmoments,
            R.drawable.ssdk_oks_classic_wechatfavorite,
            R.drawable.ssdk_oks_classic_qzone,
            R.drawable.ssdk_oks_classic_tencentweibo,
            R.drawable.ssdk_oks_classic_renren,
    };

    private int[] textList = {
            R.string.ssdk_wechat,
            R.string.ssdk_qq,
            R.string.ssdk_wechatmoments,
            R.string.ssdk_wechatfavorite,
            R.string.ssdk_qzone,
            R.string.ssdk_tencentweibo,
            R.string.ssdk_renren,
    };

    public ShareDialogAdapter(Context context) {
        this.mContext = context;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_share_dialog, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tv.setText(textList[position]);
        ImageUtils.loadImage(mContext, drawableList[position], holder.iv);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.setOnItemClick(position, textList);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return 3;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv;
        ImageView iv;

        public ViewHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.tv);
            iv = (ImageView) itemView.findViewById(R.id.iv);
        }
    }
}
